package com.sfac.day03.modules.test.repository;


import com.sfac.day03.modules.test.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface StudentRepository extends JpaRepository<Student, Integer>,
        JpaSpecificationExecutor<Student> {

    Student findFirstByStudentNameAndAge(String studentName, int age);

    @Query(nativeQuery = true,
            value = "select * from test_student where id=:id and student_name=:studentName")
    Student getStudentByIdAndStudentName(@Param("id") int id,
                                         @Param("studentName") String studentName);

    @Modifying
    @Query(nativeQuery = true, value = "update test_student set " +
            "student_name = :studentName where id = :id")
    void updateStudent(@Param("studentName")  String studentName, @Param("id")  int id);
}
